﻿using System.Collections.Generic;
using VisualWip.Core;
using VisualWip.Core.Interfaces;

namespace VisualWip.CoreTests
{
    class MySimpleClass : IPersistable
    {
        private List<MySimpleChildClass> _list;

        public MySimpleClass()
        {
            _list = new List<MySimpleChildClass>();
        }

        public string NameOne { get; set; }

        public List<MySimpleChildClass> List
        {
            get { return _list; }
        }

        public PersistenceTree Persist(string name)
        {
            var settings = new PersistenceTree(name, this);
            settings.Add(() => NameOne);
            settings.AddChildren(() => List);
            return settings;
        }

        public void Load(PersistenceTree settings)
        {
            NameOne = settings.Get(() => NameOne,string.Empty);
            foreach (var child in settings.GetChildren(() => List))
            {
                List.Add(child);
            }
        }
    }
}